// Copyright  2012 Petr TALLA. [petr.talla@gmail.com]
// This file is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY;  without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
// [http://www.gnu.org/copyleft/lesser.html]
//=============================================================================

package tc.crase.cmds;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;

import tc.common.registry.RegistrySys;
import tc.common.utility.GrView;
import tc.common.utility.TcDisplayTransf;
import tc.crase.sys.XobjectEx;
import tc.crase.sys.Xpair;

public class CmdDelete extends CmdEx {
	public CmdDelete () {
	}
	
	public void initializeDialog() {
		super.initializeDialog();
		setLabel("Delete");
		hint.setText("Select object. Next selection deletes object.");
		
		finalizeDialog();
		
		Selection.objectsAllowed = true;
		Selection.attrsAllowed = true;
	}
	
	public void enterSelected(Point pt, GrView view, Object object) {
		RegistrySys.registry.lock(); {
			
			for (int i = 0; i < Selection.selset.size(); i++)
			{	
				Object oi = Selection.selset.get(i);
				
				if (oi instanceof XobjectEx) {
					XobjectEx xobji = (XobjectEx)Selection.selset.get(i);
					if (xobji == object) object = null;
					xobji.remove();
				}
				else if(oi instanceof Xpair) {
					Xpair p = (Xpair)oi;
					XobjectEx objex = (XobjectEx)p.object;
					objex.attrRemove(p.attr);
				}
			}
			
			Selection.selset.clear();
			
			if (object instanceof XobjectEx ) {
				Selection.add((XobjectEx)object);
			}
			else if (object instanceof Xpair) {
				Xpair p = (Xpair)object;
				Selection.add(p.attr, (XobjectEx)(p.object) );
			}

		} RegistrySys.registry.unlock();
	}
	
	public void enterReset(Point pt, GrView view) {
		RegistrySys.registry.lock(); {
			Selection.clean();
		} RegistrySys.registry.unlock();
	}
	
	public void enterMove(Point pt, GrView view) {}	
	private void draw(Graphics g, TcDisplayTransf transf, Color background)	{}
}
